package com.sixth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sixth.dao.BottomArticleDao;
import com.sixth.entity.BottomArticle;
import com.sixth.service.BottomService;
import com.sixth.until.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: self-tui-education
 * @description:
 * @author: 高振杨
 * @create: 2022-05-08 17:57
 **/
@Service
public class BottomServiceImpl implements BottomService {
    @Autowired
    private BottomArticleDao bottomArticleDao;
    @Override
    public CommonResult getQianAllBottomArticle() {
        QueryWrapper<BottomArticle> bottomArticleQueryWrapper = new QueryWrapper<>();
        bottomArticleQueryWrapper.eq("is_deleted","0");
        bottomArticleQueryWrapper.eq("parent_id",0);
        //分页查询所有一级
        List<BottomArticle> bottomArticlePage = bottomArticleDao.selectList(bottomArticleQueryWrapper);
        //所有内容
        for (BottomArticle bo:bottomArticlePage){
            QueryWrapper<BottomArticle> wrapper = new QueryWrapper<>();
            wrapper.eq("parent_id",bo.getId());
            wrapper.eq("is_deleted","0");
            List<BottomArticle> bottomArticles = bottomArticleDao.selectList(wrapper);
            bo.setChildren(bottomArticles);
        }
        return new CommonResult(2000,"查询成功",bottomArticlePage);
    }
}
